Use case: CEC transmit IT mode

This use case describes how to transmit a CEC frame in Interrupt mode (IT mode) using HAL1 and HAL2.

Sequence diagram

@startuml

' Fix order of each column
participant "User application" as user
participant "<b>HAL CEC driver</b>"       as cec
participant "CEC IRQ handler" as isr

== CEC initialization / configuration ==
user -> cec : <color #Blue> HAL_CEC_Init</color>( hcec)
note right: <color #Blue>  Initializes the CEC mode according to the specified parameters in the handle.
cec --> user: HAL_OK
...

== CEC control ==
user ->cec : <color #Blue> HAL_CEC_Transmit_IT</color>( hcec, InitiatorAddress, DestinationAddress, pData, Size )
note right: <font color=blue> transmit the frame in IT mode:\n <font color=blue>- the IRQ handler processes, byte per byte, the full frame transmission.
cec --> user: HAL_OK

== CEC transmission ==
isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
note right: <font color=orange> interrupt when Tx event occurs
cec -> user : <font color=orange> HAL_CEC_TxCpltCallback() </font> user process for CEC Tx
...


group If hardware error occurs :

== CEC transmit error handling ==
 alt Tx error detected
   box "Tx error handling" #LightYellow
   isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
   note right: <font color=orange> interrupt when error: \n- Tx error
   cec -> user : <font color=orange> HAL_CEC_ErrorCallback() </font> user process CEC line error
   end box
 end

group If hardware error occurs :


@enduml

Code snippet

HAL1

HAL2

CEC_HandleTypeDef                   hcec;
uint8_t                             Tab_Tx[2];
uint8_t                             DestinationAddress;
uint8_t                             InitiatorAddress;
uint32_t                            TxSize = 0X02;





hcec.Instance                       = CEC;


hcec.Init.OwnAddress                = CEC_OWN_ADDRESS_1;
HAL_CEC_Init(&hcec);



InitiatorAddress   = 0x1;
DestinationAddress = 0x3;
Tab_Tx[0] = 0x44;
Tab_Tx[1] = 0x42;
HAL_CEC_Transmit_IT(&hcec, InitiatorAddress, DestinationAddress, (uint8_t *)&Tab_Tx, TxSize);
hal_cec_handle_t                    hcec;
uint8_t                             tx_data_frame[2];
hal_cec_header_t                    tx_header;

hal_cec_header_t                    p_rx_header;
uint8_t                             rx_data_frame[2];
uint32_t                            max_size_byte = 0x02;

uint32_t                            tx_size  = 0x02;
hal_cec_config_t                    config;

HAL_CEC_Init(&hcec, HAL_CEC);

config.own_address = HAL_CEC_OWN_ADDR_1;
HAL_CEC_SetConfig(&hcec, &config);

/* Start CEC in IT mode to enable the peripheral */
HAL_CEC_Start_IT(&hcec, &p_rx_header, rx_data_frame, max_size_byte);

tx_header.initiator_address   = 0x1;
tx_header.destination_address = 0x3;
tx_data_frame[0] = 0x44;
tx_data_frame[1] = 0x42;
HAL_CEC_Transmit_IT(&hcec, &tx_header, tx_data_frame, tx_size);

Key changes

  1. HAL2 separates initialization from configuration using HAL_CEC_Init then HAL_CEC_SetConfig.

  2. HAL2 requires starting the peripheral in IT mode using HAL_CEC_Start_IT before transmitting.

  3. HAL2 uses typed configuration and header structures (for example hal_cec_config_t and hal_cec_header_t) instead of passing raw addressing parameters.